Configurable instruction sequence generation

ABSTRACT

A configurable instruction set architecture is provided whereby a single virtual instruction may be used to generate a sequence of instructions. Dynamic parameter substitution may be used to substitute parameters specified by a virtual instruction into instructions within a virtual instruction sequence.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No. 09/788,682, filed Feb. 21, 2001, which is incorporated herein by reference in its entirety.

This application is related to the following commonly owned applications, each of which is incorporated herein by reference in its entirety: U.S. application Ser. No. 09/788,683, filed Feb. 21, 2001; U.S. application Ser. No. 09/788,670, filed Feb. 21, 2001; U.S. application Ser. No. 09/788,684, filed Feb. 21, 2001; and U.S. application Ser. No. 09/788,685, filed Feb. 21, 2001.

FIELD OF THE INVENTION

This invention relates to a technique for providing configurable instruction sequence generation, and more particularly to a technique for using virtual instructions to generate a sequence of instructions to be executed by a processor.

BACKGROUND OF THE INVENTION

Reduced instruction set computer (RISC) architectures were developed as industry trends tended towards larger, more complex instruction sets. By simplifying instruction set designs, RISC architectures make it easier to use techniques such as pipelining and caching, thus increasing system performance. By focusing on speed and simplicity of design, rather than instruction semantics, RISC architectures often result in larger executable code size than comparable complex instruction set computer (CISC) architecture machines. For example, a task that may be represented as one complex instruction in a CISC architecture may take two or more instructions in a RISC architecture. However, the performance gains resulting from increased clock speeds and increased pipelining that may be attained with a RISC architecture usually outweigh any increase in executable code size.

RISC architectures usually have fixed-length instructions (e.g., 16-bit, 32-bit, or 64-bit), with few variations in instruction format. For example, each instruction in an instruction set architecture (ISA) may have the source registers in the same location. For example, a 32-bit ISA may have source registers specified always by bits 16-20 and 21-25. This allows the specified registers to be fetched for every instruction without requiring any complex instruction decoding

SUMMARY

In one general aspect, an instruction set architecture includes a virtual instruction for generating a sequence of underlying machine instructions. A virtual instruction includes an opcode that identifies the instruction as a virtual instruction. The virtual instruction, having zero or more virtual parameters, is associated with a sequence of instructions.

Implementations may include a virtual instruction index within a virtual instruction code. The index may identify one virtual instruction from multiple available virtual instructions. Some implementations may provide virtual parameters, each of which includes a predetermined number of bits; or each of which includes either a first predetermined number of bits or a second predetermined number of bits. For example, one implementation may provide three-bit and five-bit virtual parameters.

Each virtual instruction is associated with a sequence of instructions to execute.

Each instruction in the sequence may include an instruction template identifying an instruction to be performed, a parameter selector identifying a dynamic parameter substitution, and other control information relating to the execution of that instruction within the sequence. Implementations may include one or more of the following substitutions: a parameter field, such as a register specifier, may be replaced by a virtual parameter; an opcode field may be replaced by a virtual parameter; an immediate field may be replaced by a virtual parameter; an immediate field may be replaced with a sign-extension of a virtual parameter; and an immediate field may be replaced with sign-extended or unextended concatenations of one or more virtual parameters.

The details of one or more implementations are set forth in the accompanying drawings and the description below. Other features and advantages will be apparent from the description and drawings, and from the claims.

DESCRIPTION OF DRAWINGS

FIG. 1 is a block diagram of an exemplary five-stage pipeline that may be used in a RISC architecture.

FIG. 2 is a block diagram showing parameter substitution for an exemplary configurable sequence generation instruction.

FIG. 3 is an instruction encoding for an exemplary configurable sequence generation instruction.

FIG. 4 is a flowchart showing a method of processing virtual instructions.

DETAILED DESCRIPTION

A virtual instruction is an instruction that is not executed directly by a processor. Rather, a virtual instruction causes a sequence of one or more instructions to be generated. The generated instructions then are executed by the processor. Virtual instructions may be used to provide more complex instructions in an ISA.

For example, a standard ISA may not have an operation for adding three numbers together and storing the result in a register. A particular application using the ISA may repeatedly add three numbers. The developers of a processor for the particular application may not wish to modify the processor entirely, yet significant code compaction may be obtained by providing an instruction for adding three numbers. A virtual instruction called “ADD3” that adds three numbers may be provided. Whenever the “ADD3” instruction is fetched, the system identifies the instruction as a virtual instruction and generates a corresponding sequence of instructions to add three numbers.

Virtual instructions provide a mechanism to implement a configurable instruction set architecture so that application-specific instructions or other specialized instructions may be added to an instruction set without redesigning or modifying a processor core.

Referring to FIG. 1, an exemplary microprocessor architecture that may be used to implement virtual instructions includes a five-stage pipeline in which each instruction is executed in a fixed amount of time, such as, for example, four clock cycles. The execution of each instruction is divided into five stages: instruction fetch (IF) stage 1001, register read (RD) stage 1002, arithmetic/logic unit (ALU) stage 1003, memory (MEM) stage 1004, and write back (WB) stage 1005. In the IF stage 1001, a specified instruction is fetched from an instruction cache. A portion of the fetched instruction is used to specify source registers that may be used in executing the instruction. In the read registers (RD) stage 1002, the system fetches the contents of the specified source registers. These fetched values may be used to perform arithmetic or logical operations in the ALU stage 1003. In the MEM stage 1004, an executing instruction may read/write memory in a data cache. Finally, in the WB stage 1005, values obtained by the execution of the instruction may be written back to a register.

Because some operations, such as floating point calculations and integer multiply/divide, cannot be performed in a single clock cycle, some instructions merely begin execution of an operation. After sufficient clock cycles have passed, another instruction may be used to retrieve a result. For example, an integer multiply instruction may take, for example, five clock cycles. One instruction may initiate the multiplication calculation, and another instruction may load the results of the multiplication into a register.

Virtual instructions help to offset costs that may be associated with the simplicity, elegance, and adherence to design principles provided by RISC architectures. Because multiple RISC instructions often are used instead of a single complex instruction, the overall size of executables is larger for RISC architectures than for others. Because computer storage is usually inexpensive, the increased storage costs are rarely a factor. However, in some applications, such as smart cards and application specific integrated circuits (ASICs), the available memory may be limited. In applications such as these, virtual instructions provide a mechanism for reducing the size of executables without significantly reducing pipeline efficiency.

Virtual instructions also offer benefits in consumer electronics, such as wireless telephones, global positioning system receivers, electronic games, and personal digital assistants, which have contributed to the growth of the embedded CPU market. Instead of building devices from commercially available, general-purpose components, manufacturers have increasingly turned to designs based on application-specific integrated circuits (ASICs). When CPU cores are embedded on chips complete with on-board caches and memory, the amount of storage space may be limited. Virtual instructions help to decrease the size of executables by adding the capability of executing complex instructions.

For example, a developer may need a compact code solution for embedded control applications. Some CISC products may include 32-bit instructions capable of setting, clearing, or testing a single bit in memory or input/output (I/O) space. While it generally may not be desirable to include such operations within a RISC processor core, virtual instructions provide a general mechanism in a RISC ISA that allows developers to add complex instructions appropriate to specific applications.

Referring to FIG. 2, a virtual instruction 200 is used to generate a sequence of instructions. In one implementation, virtual instruction 200 includes an index 201 and zero or more parameters, such as parameters 202 and 203. In this implementation, index 201 references a location within a virtual start table 210 to identify a start address for the appropriate sequence of instructions within an instruction expansion store 220.

In FIG. 2, index 201 is three bits long. Thus, eight virtual instructions may be specified in this implementation. As will be discussed more fully below, there is a tradeoff between the number of virtual instructions available and the amount of parameter information that may be encoded in a virtual instruction. Index 201 identifies an address within the virtual start table 210. Virtual start table 210 may be a data structure containing information about the locations of instructions corresponding to index 201. For example, virtual start table 210 may contain a start address within instruction expansion store 220 for each virtual instruction.

Instruction expansion store 220 may be implemented as a data structure containing one or more rows of data. Each row within the data structure may include an instruction to be executed as well as a dynamic parameter selector and other control information. For example, the exemplary instruction expansion store 220 shown in FIG. 2 includes the instruction “ADDI $7, 0” and the dynamic parameter selector “Imm=P1∥P0”. The ADDI instruction adds the contents of a register and an immediate value and stores the result in an indicated register. In this example, the parameters P1 and P0 are concatenated and substituted for the immediate value within the instruction, resulting in “ADDI $7,0xff. Thus, the value “0xff will be added to register $7. The next instruction in the sequence is “ADD $8, $7” with the parameter selector “rt=P3”. The ADD instruction adds the contents of two registers and stores the result in an indicated register. In this example, substitution yields the instruction “ADD $8, $7, $9” assuming the contents of P3 is “9”. Thus, the contents of registers $7 and $9 are added and stored in register $8.

A virtual program counter (PC) 230 stores the address or offset of the current instruction within the instruction expansion store 220. For example, when a virtual instruction begins execution, the start address for the corresponding instruction sequence is loaded into the virtual PC 230. As each instruction is executed, virtual PC 230 may be updated to step through the instruction expansion store 220 until the last instruction within a sequence is generated.

The last instruction within a virtual instruction expansion may be indicated in many ways. For example, information stored along with the dynamic parameter selector may be used to indicate the end of an instruction sequence. For example, if a 32-bit word is used to direct dynamic parameter substitution, one or more bits may be used to indicate that the instruction is the last within an expansion. Additionally, a new instruction may be used to indicate that the last instruction has been reached.

Substitution logic 240 is used to substitute parameters from virtual instruction 200 into instruction templates from instruction expansion store 220. The resulting instruction then may be passed on to the decode stage 250 of the processor.

Additional implementations may not use a virtual start table 210. If only a single virtual instruction is provided, or if virtual instruction expansion information is stored in a fixed or known location, then the extra level of indexing provided by virtual start table 210 may be unnecessary. In such implementations, index 201 also may not be needed, and an opcode may be sufficient to identify a particular virtual instruction and to locate the beginning of corresponding instructions within instruction expansion store 220.

Referring to FIG. 3, a virtual instruction 200 may be encoded in a 32-bit instruction architecture. In this exemplary encoding, bits 11-15 and 27-31 identify the instruction as a virtual instruction. Select bits 24-26 may be used to identify one of eight virtual instructions that can be implemented. The remaining bits specify parameters used by substitution logic 240. These may be used to identify immediate values, opcodes and/or sub-opcodes, and to identify registers to be used by instructions within a virtual instruction sequence.

During execution of a virtual instruction, the virtual instruction is held in the instruction fetch stage of the pipeline, and the PC, as opposed to the virtual PC, remains fixed at the address of the virtual instruction, while the fetch logic passes a fixed sequence of instructions to the decode stage of the pipe. When the last instruction has been issued, the PC can advance. As the entire sequence takes place at the same PC, conventional branches which manipulate the PC may not take place internal to the virtual instruction sequence—though a virtual instruction sequence could conceivably terminate with a control transfer. Conditional execution within a virtual instruction may be handled in terms of conditional moves or other predicated execution mechanisms. In the simplest implementation, any exceptions taken during the execution of the virtual instruction sequence use the address of the virtual instruction as the value of the exception return address (EPC) register or error PC, and restart the virtual instruction sequence from the beginning after completion of any exception handling. For this reason, it may be desirable to use virtual instructions that are fully restartable at any point in their execution.

Additional implementations may allow branching within a virtual instruction expansion. For example, one virtual instruction implementation may provide specific instructions for branching within a virtual instruction sequence, allowing branching within the expansion of a virtual instruction. Another implementation may redefine the semantics of branch instructions so that when conventional branch instructions are encoded within a virtual instruction expansion they exhibit different behavior. Other virtual instruction branching schemes will be apparent.

In the following discussion, “VINSTR” is used as the name for application-specific virtual instructions. Generic compiler tools may assemble and disassemble the instruction by that name, but tools also may give application-specific names to various VINSTR instantiations. For example, the generic VINSTR instruction includes the parameters as shown in FIG. 3: SELECT, P0, P1, P2, P3, and P4. The SELECT parameter determines which of the possible virtual instruction sequences to execute. The remaining parameters are used as defined by instruction sequences stored in instruction expansion store 220. The exemplary encoding shown has five parameter fields, with two having five bits and three having three bits. Additional implementations may use any number of parameters and any number of bits to encode each parameter. For example, one implementation may use three parameter fields, with each parameter having five bits.

Additional implementations may encode a virtual instruction using a code to specify the virtual instruction expansion to be performed, and one or more parameters. As will be discussed below with reference to parameter selection, there is a trade-off between compactness, complexity, and flexibility of parameter substitutions.

Referring to FIG. 4, virtual instructions may be processed using the structures described above with reference to FIG. 2. Initially, a processor reads the next instruction (step 4001). The processor then determines if the instruction is a virtual instruction (step 4002). If it is not, then the processor processes the instruction normally (step 4003). If the instruction is a virtual instruction, then the system determines the start address of the virtual instruction (step 4004). If more than one virtual instruction is supported, an index 201 may be used to specify a particular virtual instruction to execute. This index may be used to look up start values within virtual start table 210. This table may hold an address within instruction expansion store 220 of the first instruction to be executed. The system then loads the start address into the virtual PC (step 4005).

Next, the system uses the start address referenced by virtual PC 230 to lookup an instruction within instruction expansion store 220 (step 4006). For example, the virtual PC 230 shown in FIG. 2 references the instruction “ADDI $7, 0” within instruction store 220. The system also obtains a corresponding parameter selector (step 4007). This selector, which is discussed below, specifies which parameters from virtual instruction 200 to substitute into the current instruction. The system uses the instruction and parameter selector to perform parameter substitution (step 4008).

In some implementations, the parameter selector may support predicated execution of instructions within a virtual instruction expansion. Predicated execution may be implemented by using a parameter selector to indicate whether an instruction should be suppressed based on, for example, one or more virtual instruction parameters. In such an implementation, an instruction template, such as the “ADDI $7, 0” shown in FIG. 2, may include a corresponding parameter selector that indicates whether to suppress an instruction based on a parameter value. For example, the parameter selector may indicate to suppress the corresponding instruction based on the value of a parameter, such as P3. Instructions may be suppressed by issuing a NOP or other similar function.

The resulting instruction is returned as the result of IF stage 1001. The processor then executes this instruction (step 4009). Finally, the system determines if this was the last instruction within a virtual instruction sequence (step 4010). If there are additional instructions, the virtual PC is updated (step 4011) and the next instruction is loaded (step 4006). If there are no additional instructions, then the PC is updated (step 4012). In this implementation, the PC is not updated until the entire virtual instruction sequence is complete.

To support dynamic parameter substitution, the virtual instruction expansion store may contain more than just the sequence of 32-bit instructions to be presented to the pipeline. Additional information may be provided to indicate when, and how, parameters should be substituted for the literal content of fields within each 32-bit instruction.

Implementations may support any combination of the following dynamic parameter substitutions: (1) replacement of a parameter field with a translated or untranslated VINSTR parameter field; (2) replacement of an immediate field with a sign-extension of a VINSTR parameter field; (3) replacement of a portion of an immediate field with a VINSTR parameter field; (4) replacement of an immediate field with sign-extended or unextended concatenations of parameter fields; and/or (5) replacement of an instruction opcode or subopcode with a translated or untranslated VINSTR parameter.

One dynamic parameter substitution that may be provided is to replace a selected register field with a virtual instruction parameter. For example, an “ADD” instruction may have three parameters: “RS”, “RT”, and “RD”. The instruction causes the contents of the register specified by RS to be added to the contents of the register specified by RT and then stored in the register specified by RD. In virtual instruction 200, two parameters are specified, one parameter 202 having 3 bits and one parameter 203 having 5 bits. One implementation provides 32 registers, each register specified by 5 bits. In this example, parameter 202 may be translated to a 5-bit register specification. For example, one translation may be to append “00” to the beginning of the three-bit value, allowing only registers 0 to 8 to be specified.

Additional translations may be used. However, it may be necessary to limit certain expansions to certain parameter fields in order to reduce the combinatorial explosion of specifier data. There is a trade off between the increase in virtual instruction size and the decrease in virtual instruction capability that results from more restricted substitution.

Another dynamic parameter substitution that may be performed is the replacement of an immediate field with a sign-extension of a VINSTR parameter field. For example, the “ADDI” instruction allows an immediate value to be added to the contents of a register. This substitution allows the immediate value field to be specified by one of the virtual instruction parameter fields. The immediate field may be 16 bits, while the virtual instruction parameter may be only five bits. However, the 5-bit value may be sign extended to 16 bits. Sign extension may not be needed if the instructions are stored initially with zeros in the immediate field.

Another dynamic parameter substitution includes the replacement of immediate fields with sign-extended or unextended concatenations of parameter fields. For example, 8-bit immediate values may be created by concatenating 3-bit and 5-bit virtual instruction parameter fields. Additionally, dynamic parameter substitution may include the replacement of an instruction opcode or sub-opcode with a translated or untranslated VINSTR parameter field. This allows, for example, one or more instructions in a virtual instruction sequence to be selected by one or more VINSTR parameter.

In addition to virtual instruction implementations using hardware, (e.g., within a microprocessor or microcontroller) implementations also may be embodied in software disposed, for example, in a computer usable (e.g., readable) medium configured to store the software (i.e., a computer readable program code). The program code causes the enablement of the functions or fabrication, or both, of the systems and techniques disclosed herein. For example, this can be accomplished through the use of general programming languages (e.g., C, C++), hardware description languages (HDL) including Verilog HDL, VHDL, AHDL (Altera HDL) and so on, or other available programming and/or circuit (i.e., schematic) capture tools. The program code can be disposed in any known computer usable medium including semiconductor, magnetic disk, optical disk (e.g., CD-ROM, DVD-ROM) and as a computer data signal embodied in a computer usable (e.g., readable) transmission medium (e.g., carrier wave or any other medium including digital, optical, or analog-based medium). As such, the code can be transmitted over communication networks including the Internet and intranets.

It is understood that the functions accomplished and/or structure provided by the systems and techniques described above can be represented in a core (e.g., a microprocessor core) that is embodied in program code and may be transformed to hardware as part of the production of integrated circuits. Also, the systems and techniques may be embodied as a combination of hardware and software. Accordingly, other implementations are within the scope of the following claims. 

1. A microprocessor providing an extendable instruction set architecture, the microprocessor comprising: a memory for storing at least one virtual instruction that includes an index and at least one parameter; a virtual instruction expansion store including at least one instruction template and at least one parameter selector; and substitution logic that forms a sequence of at least one expanded instruction, wherein bits of an opcode of the at least one expanded instruction are formed from the at least one parameter in a manner specified by the at least one parameter selector.
 2. The microprocessor of claim 1, wherein the bits of the opcode are formed by substituting at least one bit of the at least one parameter into the at least one instruction template.
 3. The microprocessor of claim 1, wherein the bits of the opcode are formed by substituting a translation of bits of the at least one parameter into the at least one instruction template.
 4. The microprocessor of claim 1, wherein the bits of the opcode are formed by zero-extending at least one bit of the at least one parameter.
 5. The microprocessor of claim 1, further comprising: a virtual start table coupled to the virtual instruction expansion store.
 6. The microprocessor of claim 5, further comprising: a virtual program counter coupled between the virtual start table and the virtual instruction expansion store.
 7. The microprocessor of claim 1, wherein the virtual instruction includes a first parameter having a first number of bits and a second parameter having a second number of bits.
 8. The microprocessor of claim 7, wherein the first parameter includes at least three bits.
 9. The microprocessor of claim 8, wherein the second parameter includes at least five bits.
 10. A method for generating a sequence of at least one expanded instruction from a virtual instruction, comprising: receiving a virtual instruction that includes an index and at least one parameter; identifying an instruction template and a parameter selector based on the index; and forming a sequence of at least one expanded instruction, wherein bits of an opcode of the at least one expanded instruction are formed from the at least one parameter in a manner specified by the parameter selector.
 11. The method of claim 10, wherein the forming step comprises: substituting at least one bit of the at least one parameter into the instruction template.
 12. The method of claim 10, wherein the forming step comprises: substituting a translation of bits of the at least one parameter into the instruction template.
 13. The method of claim 10, wherein the forming step comprises: zero-extending at least one bit of the at least one parameter.
 14. The method of claim 10, wherein the receiving step comprises receiving a virtual instruction including a first parameter having a first number of bits and a second parameter having a second number of bits.
 15. The method of claim 14, wherein the receiving step comprises receiving a virtual instruction including a first parameter having at least three bits and a second parameter having at least five bits.
 16. A computer-readable medium comprising a microprocessor embodied in software, the microprocessor including: a memory for storing at least one virtual instruction that includes an index and at least one parameter; a virtual instruction expansion store including at least one instruction template and at least one parameter selector; and substitution logic that forms a sequence of at least one expanded instruction, wherein bits of an opcode of the at least one expanded instruction are formed from the at least one parameter in a manner specified by the at least one parameter selector.
 17. The computer readable medium of claim 16, wherein the bits of the opcode are formed by substituting at least one bit of the at least one parameter into the at least one instruction template.
 18. The computer readable medium of claim 16, wherein the bits of the opcode are formed by substituting a translation of bits of the at least one parameter into the at least one instruction template.
 19. The computer readable medium of claim 16, wherein the bits of the opcode are formed by zero-extending at least one bit of the at least one parameter.
 20. The computer readable medium of claim 16, wherein the microprocessor includes: a virtual start table coupled to the virtual instruction expansion store.
 21. The computer readable medium of claim 20, wherein the microprocessor includes: a virtual program counter coupled between the virtual start table and the virtual instruction expansion store.
 22. The computer readable medium of claim 16, wherein the virtual instruction includes a first parameter having a first number of bits and a second parameter having a second number of bits.
 23. The computer readable medium of claim 16, wherein the microprocessor is embodied in hardware description language software.
 24. The computer readable medium of claim 16, wherein the microprocessor is embodied in one of Verilog hardware description language software and VHDL hardware description language software.
 25. A pipelined microprocessor, comprising: instruction decode logic; a program counter for indicating a current location in an instruction sequence; instruction fetch logic for fetching an instruction from the current location in the instruction sequence; a virtual program counter; and a virtual instruction expansion store; wherein if the instruction fetch logic determines that the fetched instruction is a virtual instruction, the instruction fetch logic is adapted to: hold the virtual instruction in the instruction fetch logic; maintain the program counter at the address of the virtual instruction; pass one of a plurality of instructions obtained from a virtual instruction expansion store to the instruction decode logic; increment the virtual program counter to select and pass a next instruction from the plurality of instructions to the instruction decode logic until either each of the plurality of instructions has executed or an exception occurs; and after the plurality of instructions have been executed or an exception occurs, advance the program counter.
 26. The pipelined microprocessor of claim 25, wherein the virtual instruction expansion store includes at least on instruction template and at least one parameter selector.
 27. The pipelined microprocessor of claim 25, wherein the plurality of instructions include a conditional move instruction.
 28. The pipelined microprocessor of claim 25, wherein the plurality of instructions include an instruction for branching.
 29. The pipelined microprocessor of claim 25, wherein the plurality of instructions terminate with a control transfer instruction.
 30. A method for implementing virtual instructions in a processor that includes a virtual program counter, a virtual instruction expansion store, and instruction decode logic, comprising: fetching a virtual instruction; determining a start address for the virtual instruction; loading the start address in the virtual program counter; passing one of a plurality of instructions obtained from the virtual instruction expansion store to the instruction decode logic; and incrementing the virtual program counter to select and pass a next instruction from the plurality of instructions to the instruction decode logic until either each of the plurality of instructions has executed or an exception occurs. 